import {resourceService} from "@kordar/easyui-tpl";

export async function bucketList() {
    let {data} = await resourceService.list("bucket", {pageSize: 1000})
    let rows = []
    for (let i = 0; i < data.length; i++) {
        let item = data[i];
        rows.push({
            id: item['id'],
            name: item['name'],
            remark: item['remark'],
            driver: item['driver'],
            config: JSON.parse(item['config']),
        })
    }
    return rows
}

export function getBucketName(bucketList, bucketId) {
    for (let i = 0; i < bucketList.length; i++) {
        let item = bucketList[i];
        if (item.id == bucketId) {
            return item.name;
        }
    }
    return "";
}

export function toBucketSelect(buckets) {
    let data = []
    for (let i = 0; i < buckets.length; i++) {
        let item = buckets[i];
        data.push({
            value: item.id, text: item.name
        })
    }
    return data;
}